package com.detection.hikvision.domain;

import com.detection.common.domain.YqCameraEvent;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * 事件基础类
 * @author LH
 * @date 2022/9/13 10:51
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EventVo {

    private String eventId;

    private String srcIndex;

    private String srcType;

    private String srcName;

    private Integer eventType;

    private Integer status;

    private Integer eventLvl;

    private Integer timeout;

    private String happenTime;

    private String srcParentIndex;

    private Object data;


    public YqCameraEvent toCameraEvent(YqCameraEvent event) throws ParseException, JsonProcessingException {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSXXX");
        if(null == event){
            event = new YqCameraEvent();
        }
        event.setEventId(eventId);
        event.setSrcIndex(srcIndex);
        event.setSrcType(srcType);
        event.setSrcName(srcName);
        event.setEventType(eventType);
        event.setStatus(status);
        event.setEventLvl(eventLvl);
        event.setTimeout(timeout);
        event.setHappenTime(dateFormat.parse(happenTime));
        event.setSrcParentIndex(srcParentIndex);
        event.setData(new JsonMapper().writerWithDefaultPrettyPrinter().writeValueAsString(data));
        return event;
    }
}
